Home:ALL Converter>Can anybody please assist with syntax in a function in postgresql (from mysql)

Can anybody please assist with syntax in a function in postgresql (from mysql)

Ask Time:2022-03-03T20:46:20         Author:Janes Krige

Json Formatter

I am trying to create the following function in PostgreSQL but get the following error. This is from a MySQL procedure that I need to convert to PostgreSQL. I am failing to convert the syntax to PostgreSQL. I am a beginner in PostgreSQL. Please assist me.

CREATE OR REPLACE FUNCTION public.usp_failed_analyze4()
RETURNS TABLE(status varchar) as
$BODY$
    SET @maxdate = (SELECT MAX(analyzetime) FROM  wp_analyze_history);
    SET @maxdateint = (SELECT DATEDIFF(NOW() ,MAX(analyzetime)) FROM  wp_analyze_history);
    SET @STATUS = SELECT Status from wp_analyze_history WHERE Status NOT IN ('OK','Table is already up to date','The Analyze task DID NOT run!') AND  analyzetime = @maxdate);
    SET @STATUSNOTRUN = 'The Analyze task DID NOT run!';
    IF @maxdateint > 7
    THEN SELECT @STATUSNOTRUN;
    ELSE SELECT @STATUS as "";
$BODY$
    LANGUAGE sql;

error: ERROR: syntax error at or near "@" Position: 109

Author:Janes Krige,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71337453/can-anybody-please-assist-with-syntax-in-a-function-in-postgresql-from-mysql
yy